package com.example.dangerouscargodriver.widget;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.dangerouscargodriver.R;
import com.example.dangerouscargodriver.entry.MessageInfo;
import com.example.dangerouscargodriver.ui.activity.CompanyDetailActivity;
import com.example.dangerouscargodriver.ui.activity.MyOrderDetailInfoActivity;
import com.example.dangerouscargodriver.ui.activity.MyResourceDetailActivity;
import com.example.dangerouscargodriver.ui.activity.PersonalTruckDetailInfoActivity;
import com.example.dangerouscargodriver.ui.activity.ResourceDetailActivity;

public class MessageInfoView extends LinearLayout implements View.OnClickListener {

    private static final String TAG = "MessageInfoView";
    private TextView mMessageTitle = null;
    private TextView mMessageContent = null;
    private TextView mSeeDetail = null;
    private TextView mMessageCreateTime = null;
    private LinearLayout mLayout = null;

    private Context mContext = null;
    private MessageInfo mMessageInfo = null;

    private OnReadNoticeListener mListener = null;

    public MessageInfoView(Context context, MessageInfo info) {
        this(context, null, info);
    }

    public MessageInfoView(Context context, AttributeSet attrs, MessageInfo info) {
        this(context, attrs, 0, info);
    }

    public MessageInfoView(Context context, AttributeSet attrs, int defStyleAttr, MessageInfo info) {
        super(context, attrs, defStyleAttr);
        init(context, attrs, info);
    }

    public void init(Context context, AttributeSet attrs, MessageInfo info) {
        mContext = context;
        mMessageInfo = info;
        View itemLayout = LayoutInflater.from(context).inflate(R.layout.layout_message_info_item, this);
        mMessageTitle = itemLayout.findViewById(R.id.tv_message_title);
        mSeeDetail = itemLayout.findViewById(R.id.tv_see_detail);
        mMessageContent = itemLayout.findViewById(R.id.tv_message_content);
        mMessageCreateTime = itemLayout.findViewById(R.id.tv_message_create_time);

        //执行绑定数据的操作
        mMessageTitle.setText(mMessageInfo.getTitle());
        mMessageContent.setText(mMessageInfo.getContent());
        mMessageCreateTime.setText(mMessageInfo.getCreate_time());

        mSeeDetail.setOnClickListener(this);
    }

    public void bindData(MessageInfo info){
        if(info != null){
        }
    }

    public void setOnReadNoticeListener(OnReadNoticeListener listener){
        mListener = listener;
    }

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.tv_see_detail){
            if(mListener != null){
                mListener.onReadNotice(mMessageInfo);
            }
        }
    }

    public interface OnReadNoticeListener{
        public void onReadNotice(MessageInfo info);
    }
}
